<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Facelet Title</title> 
    </h:head>
    <h:body>
        <ui:composition template="./BannersAndMenusTemplate.jsf">

            <ui:define name="content"> 
                <p:panel header="All References">


                    <h:form id="form" rendered="#{user.login}">   
  
                        <p:dataTable id="dataTable2" var="Reference" value="#{user.getallReferences()}" widgetVar="Reference"   
                                     emptyMessage="No References found with given criteria" 
                                     selection="#{user.selectedReference}" selectionMode="single"  rowKey="#{Reference.id}"
                                     paginator="#{user.checkIfTenOrMore('ref')}" rows="10" rowsPerPageTemplate="5,10,15" lazy="false"  
                                     paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}" >  

                            
                            <p:ajax event="rowSelect" listener="#{user.onRowSelectREF}"    
                                    update=":form:dataTable2" />  
                            <p:ajax event="rowUnselect" listener="#{user.onRowUnselectREF}" update=":form:dataTable2"/>  
                            
                            <f:facet name="footer">   

                                <p:commandButton value="Add" icon="ui-icon-refresh"
                                                 action="#{user.gotoNewReference()}" update=":form:dataTable2"/>   





                                <p:commandButton  id="showDialogButton" rendered="#{user.renderOnRowSelectREF}" value="Delete" onclick="confirmation.show();" type="button" icon="ui-icon-close"
                                                  />   
                                
                                <p:growl id="messages" showDetail="true" sticky="false"/>  

                                <p:confirmDialog id="confirmDialog" message="Are you sure about delete the reference?"  
                                                 header="Delete reference!" severity="alert" widgetVar="confirmation">  

                                    <p:commandButton id="confirm" value="Yes" update=":form" oncomplete="confirmation.hide()"  
                                                     actionListener="#{user.deleteReference}" ajax="true"/>   
                                    <p:commandButton id="decline" value="No" onclick="confirmation.hide();" type="button" />   

                                </p:confirmDialog>  

 

                                <p:commandButton  rendered="#{user.renderOnRowSelectREF}" value="Edit" icon="ui-icon-pencil"
                                                  action = "#{user.gotoEditReference}"/>   


                                <p:commandButton  rendered="#{user.renderOnRowSelectREF}" value="Details" icon="ui-icon-newwin"
                                                  action = "#{user.gotoViewReference}"/>  
                            </f:facet>     

                            <p:column  filterBy="#{Reference.title}"   
                                       headerText="Title"  
                                       filterMatchMode="contains">  
                                <h:outputText value="#{Reference.title}" />   </p:column> 

                            <p:column  filterBy="#{Reference.rYear}"   
                                       headerText="Year"  
                                       filterMatchMode="contains">  
                                <h:outputText value="#{Reference.rYear}" />  </p:column> 

                            <p:column  filterBy="#{Reference.type}"   
                                       headerText="Type of reference"   
                                       filterMatchMode="contains">  
                                <h:outputText value="#{Reference.type}" />   

                            </p:column>  


                        </p:dataTable> 

                    </h:form>



                </p:panel>
            </ui:define>

        </ui:composition>
    </h:body>
</html>

